home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- *
- * WComboBox -- Wrapper for the combobox control.
- *
- * Events:
- *
- * BeginOwnerDraw -- Called before the first DrawItem.
- *
- * Change -- Occurs whenever the edit box changes.
- *
- * DataAvailable --
- *
- * DataClose --
- *
- * DataOpen --
- *
- * DataRequest --
- *
- * DoubleClick -- When an item in the list box is double-clicked.
- *
- * DrawItem -- Called for owner-draw.
- *
- * DropDown -- The list box is about to drop down.
- *
- * DropDownSelect --
- *
- * EndOwnerDraw -- Called after last DrawItem.
- *
- * Select -- When an item in the list box has been selected.
- *
- *************************************************************************/
-
- #ifndef _WCOMBOX_HPP_INCLUDED
- #define _WCOMBOX_HPP_INCLUDED
- #pragma once
-
- #ifndef _WNO_PRAGMA_PUSH
- #pragma pack(push,8);
- #pragma enum int;
- #endif
-
- #ifndef _WCONTROL_HPP_INCLUDED
- # include "wcontrol.hpp"
- #endif
-
- #ifndef _WLOCALE_HPP_INCLUDED
- # include "wlocale.hpp"
- #endif
-
- #ifndef _WDRAWITM_HPP_INCLUDED
- # include "wdrawitm.hpp"
- #endif
-
- #ifndef _WDATATRG_HPP_INCLUDED
- # include "wdatatrg.hpp"
- #endif
-
- //
- // ComboBox styles
- //
-
- #define WCBSDefault ((WStyle)0x50200201L) // WS_VISIBLE|CBS_HASSTRINGS|CBS_SIMPLE|WS_CHILD|WS_VSCROLL
- #define WCBSSimple ((WStyle)0x00000001L) // CBS_SIMPLE
- #define WCBSDropDown ((WStyle)0x00000002L) // CBS_DROPDOWN
- #define WCBSDropDownList ((WStyle)0x00000003L) // CBS_DROPDOWNLIST
- #define WCBSOwnerDrawFixed ((WStyle)0x00000010L) // CBS_OWNERDRAWFIXED
- #define WCBSOwnerDrawVariable ((WStyle)0x00000020L) // CBS_OWNERDRAWVARIABLE
- #define WCBSAutoHScroll ((WStyle)0x00000040L) // CBS_AUTOHSCROLL
- #define WCBSOEMConvert ((WStyle)0x00000080L) // CBS_OEMCONVERT
- #define WCBSSort ((WStyle)0x00000100L) // CBS_SORT
- #define WCBSHasStrings ((WStyle)0x00000200L) // CBS_HASSTRINGS
- #define WCBSNoIntegralHeight ((WStyle)0x00000400L) // CBS_NOINTEGRALHEIGHT
- #define WCBSDisableNoScroll ((WStyle)0x00000800L) // CBS_DISABLENOSCROLL
- #define WCBSUpperCase ((WStyle)0x00002000L) // CBS_UPPERCASE
- #define WCBSLowerCase ((WStyle)0x00004000L) // CBS_LOWERCASE
-
- struct WComboBoxFDXData {
- WStringArray items;
- WInt selected;
- };
-
- class WCMCLASS WComboBox : public WControl {
- WDeclareSubclass( WComboBox, WControl );
-
- public:
-
- /**************************************************************
- * Constructors and Destructors
- **************************************************************/
-
- WComboBox();
-
- ~WComboBox();
-
- /**************************************************************
- * Properties
- **************************************************************/
-
- // Count
- //
- // Returns the number of items in the list box, or negative
- // if an error occurs.
-
- WInt GetCount() const;
-
- // DataColumns
- //
- // DataTarget property
-
- WString GetDataColumns() const;
- WBool SetDataColumns( const WString & cols );
-
- // DataLookupColumns
- //
- // DataTarget property
-
- WString GetDataLookupColumns() const;
- WBool SetDataLookupColumns( const WString & cols );
-
- // DataLookupSource
- //
- // DataTarget property
-
- WDataSource *GetDataLookupSource() const;
- WBool SetDataLookupSource( WDataSource *source );
-
- // DataSource
- //
- // DataTarget property
-
- WDataSource *GetDataSource() const;
- WBool SetDataSource( WDataSource *source );
-
- // FDXDataSource
-
- WBool SetFDXDataSource( WStringArray * fdxDataSource );
- WBool SetFDXDataSource( WInt * fdxDataSource );
-
- // DroppedDown
- //
- // Get/set the drop down state. TRUE = dropped, FALSE = not.
-
- WBool GetDroppedDown() const;
- WBool SetDroppedDown( WBool show );
-
- // EditSelection
- //
- // The current selection in the edit control. The
- // selection points start at 0 and occur between the characters.
- // Note that no value can be greater than 65534. When setting,
- // set start=-1 to deselect everything, or set end=-1 to
- // select from start to end of text.
-
- WRange GetEditSelection() const;
- WBool SetEditSelection( const WRange & editSelection );
-
- // ExtendedUI
- //
- // Controls whether or not the combobox uses the extended UI.
- // If TRUE, the F4 key does nothing and the down arrow key
- // opens the drop-down list. Otherwise the F4 key opens
- // the drop-down list and the down arrow key moves the
- // current selection.
-
- WBool GetExtendedUI() const;
- WBool SetExtendedUI( WBool on );
-
- // Selected
- //
- // Get/set the selected item in the list box. A selected
- // value of -1 means nothing is selected. Setting the value
- // to -1 clears the selected entry and the edit box.
-
- WInt GetSelected() const;
- WBool SetSelected( WInt index );
-
- // SendDeleteItem
- //
- // If TRUE, DeleteItem events will be triggered consistently
- // across all platforms if non-null user data has been
- // set for any items in the combobox.
-
- WBool GetSendDeleteItem() { return _sendDeleteItem; }
- WBool SetSendDeleteItem( WBool set ) { _sendDeleteItem = set; return TRUE; }
-
- // Sort
- //
- // Get/set the sort mode.
-
- WBool GetSort() const;
- WBool SetSort( WBool sort, WBool clone=FALSE );
-
- // Locale (for type of sort)
- //
- //
- WBool SetLocale( WLocaleID locID );
- WLocaleID GetLocale();
-
- // TextLimit
- //
- // Get/set the maximum # of characters the user can type
- // into the edit box. 0 or negative means set to maximum.
-
- WLong GetTextLimit() const;
- WBool SetTextLimit( WLong limit );
-
-
- /**************************************************************
- * Methods
- **************************************************************/
-
- // Add
- //
- // Adds an item. If itemNumber is set to >= 0, item is
- // inserted at the given location. If the list is sorted
- // and itemNumber is set to -1, inserts in correct spot;
- // otherwise adds to the end. Can also set optional
- // per-item data.
- // Returns the index of the item, or a negative value in
- // case of error.
-
- WInt Add( const WChar * string, WInt itemNumber=-1,
- void * itemUserData=NULL, WBool addInSortedOrder=TRUE );
-
- // Clear
- //
- // Clear the edit box.
-
- void Clear();
-
- // Copy
- //
- // Copy the selected area into the clipboard.
-
- WBool Copy();
-
- // Cut
- //
- // Copy the selected area into the clipboard then clear it.
-
- void Cut();
-
- // DataAddLookupItem
- //
- // Allows the user to manually fill the list with lookup items.
- // This is an alternative method to setting the DataLookupSource
- // and DataLookupColumns properties.
-
- WInt DataAddLookupItem( const WDataValue & value,
- const WChar * string = NULL,
- WInt itemNumber=-1, void * itemUserData=NULL,
- WBool addInSortedOrder=TRUE );
-
- // DataFetchLookupItems
- //
- // Forces the lookup items to be fetched from the database
- // (according to the DataLookupSource and DataLookupColumns
- // properties).
- // This is normally done when either data source is opened...
-
- WBool DataFetchLookupItems();
-
- // Delete
- //
- // Deletes the specified item. If an item's data is set,
- // invokes the WDeleteItemEvent event first. Returns the count
- // of items remaining in the list, or negative if error occurs.
-
- WInt Delete( WInt itemNumber );
-
- // DeleteAll
-
- WBool DeleteAll ();
-
- // Find
- //
- // Finds the first string that matches a given prefix. The
- // search starts immediately AFTER the given index (use -1
- // to search from the beginning) and wraps when the bottom
- // is reached. The search is not case-sensitive. If exact
- // is specified, the string must match exactly, otherwise
- // a prefix match is done. Returns the index of the match
- // or negative on error.
-
- WInt Find( const WChar *match, WInt startAfter=-1,
- WBool exact=FALSE ) const;
-
- // Paste
- //
- // Paste the clipboard text into the current selection.
-
- void Paste();
-
- // Reset
- //
- // Reset (clear) both the list box and edit box.
-
- void Reset();
-
- // Select
- //
- // Find and select an item. Searches for the first item whose
- // prefix matches (case-insensitive) the given string. Returns
- // the index of the new selected item, or negative if an error
- // occurs. If startAfter is -1, search starts at first item.
-
- WInt Select( const WChar * match, WInt startAfter=-1 );
-
- // Undo
- //
- // Undo the last change to the edit box.
-
- WBool Undo();
-
- /**************************************************************
- * Item Properties
- **************************************************************/
-
- // DataLookupValue
- //
- // Get the lookup value associated with the given list item.
-
- WDataValue GetDataLookupValue( WInt itemNumber ) const;
-
- // Text
- //
- // Get the text of a specific item in the list. First two
- // versions return a WString, which is set to a null string
- // if an error occurs. Last version copies it into a buffer
- // and returns the length, or a negative value.
-
- WString GetText( WInt itemNumber ) const;
-
- // TextLength
- //
- // Get the length of the text of an item in the list (without
- // the null character). A negative value is returned in case
- // of error.
-
- WInt GetTextLength( WInt itemNumber ) const;
-
- // UserData
- //
- // Get/set per-item data. When getting data, a value of
- // ((void *)-1) for the itemUserData indicates an error.
-
- WBool SetUserData( WInt itemNumber, void * itemData );
- void * GetUserData( WInt itemNumber ) const;
-
- // Height
- //
- // Get/set height of listbox items or the edit box. If
- // itemNumber is -1, works on edit box, otherwise must be
- // 0 if the WCBSOwnerDrawVariable flag is not set, otherwise
- // it is the index of the item. For get, negative value
- // is returned to indicate error.
-
- WInt GetHeight( WInt itemNumber ) const;
- WBool SetHeight( WInt itemNumber, WInt height );
-
- /**************************************************************
- * Others
- **************************************************************/
-
- virtual size_t GetTextLength() const;
-
- virtual WBool FDXIn();
-
- virtual WBool FDXOut();
-
- virtual WBool FillDragEventData( WDragEventData & event ) const;
-
- WBool DestroyEventHandler( WWindow * window, WEventData * event );
-
- WLong ProcessChildMessage( WWindowHandle hWnd, WUInt msg,
- WUInt wParam, WLong lParam );
-
- virtual WBool ProcessMessage( const WMessage & msg,
- WLong & returns );
-
- virtual WBool SetHeight( const WInt & height, WBool update=TRUE );
- virtual WInt GetHeight() const;
-
- virtual WBool SetText( const WString & str );
- virtual WString GetText() const;
-
- virtual WBool SetUserData( void * userData );
- virtual void * GetUserData() const;
-
- virtual WBool ProcessCommand( WUInt id, WNotify code,
- WNotifyInfo info, WLong & returns );
- virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
- void * data=NULL );
-
- virtual WBool DefaultProcess( const WMessage & msg,
- WLong & returns );
-
- virtual WBool AttachToWindow( WWindowHandle hWnd, WBool destroy,
- WBool subclass );
- virtual WWindowHandle DetachFromWindow();
-
- virtual WStyle GetDefaultStyle() const;
- virtual WStyle GetDefaultExtendedStyle() const;
- virtual const WChar * InitializeClass();
-
- virtual WBool IgnoreDeleteItem();
-
- WBool DeleteItemHandler( WComboBox *, WDeleteItemEventData *ev );
-
- // Event handlers for the DataTarget
-
- WBool DataOpenHandler( WComboBox *, WDataOpenEventData *ev );
- WBool DataCloseHandler( WComboBox *, WDataCloseEventData *ev );
- WBool DataAvailableHandler( WComboBox *, WDataAvailableEventData *ev );
- WBool DataRequestHandler( WComboBox *, WDataRequestEventData *ev );
- WBool DataLookupItemHandler( WComboBox *, WDataLookupItemEventData *ev );
-
- /**************************************************************
- * Overrides
- **************************************************************/
-
- virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
- virtual WBool SetFont( const WFont & font, WBool preserveSize=TRUE );
- virtual WRect GetRectangle( WBool absolute=FALSE ) const;
- virtual WBool Move( const WRect & rectangle, WBool update=TRUE );
- virtual WBool Move( const WRect & rectangle, WDeferMoveHandle & dwp );
- virtual WBool Move( const WPoint & point, WBool update=TRUE );
- virtual WBool Move( const WPoint & point, WDeferMoveHandle & dwp );
-
- /**************************************************************
- * Internal
- **************************************************************/
-
- protected:
-
- WBool IndirectUserData( WBool indirect );
-
- WBool SetRealUserData( WInt itemNumber, void * itemData );
- void * GetRealUserData( WInt itemNumber ) const;
-
- WBool AllocLookup();
-
- void RemoveLookupItems();
-
- virtual WBool LoadWindow( WWindow * parent,
- const WResourceID & id,
- WModuleHandle module=_ApplicationModule );
-
- virtual WBool MakeWindow( WWindow * parent, WUInt id,
- const WChar *className,
- const WChar *title, const WRect & r,
- WStyle wstyle, WStyle exStyle,
- void * data=NULL );
-
- /**************************************************************
- * Data members
- **************************************************************/
-
- protected:
-
- WWindowHandle _editChild;
- WCallbackProc _editWndProc;
- WWindowHandle _listChild;
- WCallbackProc _listWndProc;
- WLong _textLimit;
- WBool _indirectUserData;
- WDataLookup * _dataLookup;
- WDataTargetCell * _dataTarget;
- WInt _initialValue;
- WBool _wasEnabled;
- WBool _wasPainting;
- WBool _ignoreChange;
- WStringArray * _fdxDataSourceStringArray;
- WInt * _fdxDataSourceInt;
- WInt _realHeight;
- WBool _userDataWasSet;
- WBool _sendDeleteItem;
- WBool _ignoreDeleteItem;
- };
-
-
- #ifndef _WNO_PRAGMA_PUSH
- #pragma enum pop;
- #pragma pack(pop);
- #endif
-
- #endif // _WCOMBOX_HPP_INCLUDED
-